package com.autumn.jvm.jvm;

import sun.misc.Launcher;

import java.net.URL;

/**
 * @author: Autumn
 * @describe:
 * @date: 2022/9/29
 * @modified By:
 */
public class TestJDKClassLoader {
    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader());
        System.out.println(TestJDKClassLoader.class.getClassLoader());
        System.out.println("----------------------------------------");

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();
        System.out.println("the bootstrapClassLoader >>> " + bootstrapClassLoader);
        System.out.println("the extClassLoader >>> " + extClassLoader);
        System.out.println("the appClassLoader >>> " + appClassLoader);
        System.out.println("----------------------------------------");

        System.out.println("bootstrapClassLoader加载以下文件：");
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL url : urLs) {
            System.out.println(url);
        }
        System.out.println("----------------------------------------");

        System.out.println("extClassLoader加载了以下文件：");
        System.out.println(System.getProperty("java.ext.dirs"));
        System.out.println("----------------------------------------");

        System.out.println("appClassLoader加载了以下文件：");
        System.out.println(System.getProperty("java.class.path"));

        //运行结果如下
        /*
        null
        sun.misc.Launcher$ExtClassLoader@33c7353a
        sun.misc.Launcher$AppClassLoader@18b4aac2
        ----------------------------------------
        the bootstrapClassLoader >>> null
        the extClassLoader >>> sun.misc.Launcher$ExtClassLoader@33c7353a
        the appClassLoader >>> sun.misc.Launcher$AppClassLoader@18b4aac2
        ----------------------------------------
        bootstrapClassLoader加载以下文件：
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/resources.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/rt.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/sunrsasign.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/jsse.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/jce.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/charsets.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/lib/jfr.jar
        file:/C:/Program%20Files/Java/jdk1.8.0_301/jre/classes
        ----------------------------------------
        extClassLoader加载了以下文件：
        C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
        ----------------------------------------
        appClassLoader加载了以下文件：
        C:\Program Files\Java\jdk1.8.0_301\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\access-bridge-64.
        jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\management- agent.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_301\jre\lib\rt.jar;D:\SelfProject\demo\target\classes;D:\.m2\repository\org\projectlombok\lombok\1.18.24\lombok-1.18.24.jar;D:\.m2\repository\com\google\guava\guava\21.0\guava-21.0.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2021.3\lib\idea_rt.jar
        */
    }
}
